* graphrif.do
* Program to graph results of RIF regressions

clear

cap program drop graphmultirif

program define graphmultirif

syntax, master(string) ster(string) folders(string) qtiles(numlist) specs(string) times(string) axes(string) [rareaopts(string) lineopts(string) twowayopts(string) bites(string) freq(string) subs(string) patterns(string)]

	
	cd "`master'/`ster'"

	
	
	tempvar qtile 
	gen `qtile'=.
	
	* How many lines?
	loc lines: word count `specs'
	
	forv l=1(1)`lines' {
		tempvar beta`l'
		gen `beta`l''=.
	}
	
	if "`bite'"=="" loc bite "bite"	
	if "`freq'"=="" loc freq "mensual"

	loc count: word count `qtiles'
	set obs `count'
	loc i=1
	foreach q in `qtiles' {
		qui replace `qtile'=`q' in `i'
		
		forv l=1(1)`lines' {
			loc spec: word `l' of `specs'
			loc time: word `l' of `times'
			loc bite: word `l' of `bites'
			loc folder: word `l' of `folders'
			if "`subs'"=="" {
				loc sub "_*_"
			}
			else {
				loc sub: word `l' of `subs'
				loc sub "*_`sub'_*"
			}
			loc dir=c(pwd)
			cd `folder'
			* loc file: dir . files "reg_emp_bp*_p`q'.ster"
			loc file: dir . files "`spec'_`time'_`bite'_*_`freq'`sub'p`q'.ster"
			* di "`file'"
			est use `file'
			* di _se[treat]
			
			qui replace `beta`l''=_b[treat] in `i'
			* li `beta`l''
			cd `dir'
		}
		*discard
		loc i=`i'+1
		
	}
	
	loc colors "black black black black black black black black"
	if "`patterns'"=="" loc patterns "solid dash dash_dot dot shortdash shortdash_dot longdash longdash_dot"
	
	loc plotlines ""
	loc i=1
	forv l=1(1)`lines' {
		loc color: word `i' of `colors'
		loc pattern: word `i' of `patterns'
		loc axis: word `i' of `axes'
		loc plotlines "`plotlines' (line `beta`l'' `qtile', lcolor(`color') lpattern(`pattern') yaxis(`axis'))"
		loc i=`i'+1
	}
	*loc plotlines "(line `plotlines' `qtile', lcolor() lpattern(solid dash dot dash_dot))"
	
	twoway `plotlines' (function y=0, lcolor(gray) range(5 90)) , `twowayopts'
	* twoway (rarea `ll' ul q, bcolor(gs13)) (line beta q), legend(label(2 "Coef") label(1 "95 % CI") order(2 1))
end

	


